package hotel_price;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class RedTest extends Reducer<Text, IntWritable,Text, DoubleWritable> {
    Text k = new Text();
    DoubleWritable v = new DoubleWritable();
    double count = 0;
    double sum;
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        for (IntWritable i:values){
            sum+=i.get();
            count++;
        }
        v.set(sum/count);
        k.set(key+"的酒店参与的有"+count+"所");
        context.write(k,v);
        sum=0;
        count=0;
    }
}
